home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AEObjPak.c (Orignal name: AEObjectPacking.c)
-
- Contains:
-
- Owned by: Nick Pilch
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 9/29/94 RA 1189812: Mods for 68K build.
- <2> 8/19/94 NP 1181622: Ownership fix.
- <3> 2/7/94 NP Tiger Team doings.
- <2> 7/21/93 NP Fixed #include
- <1> 7/21/93 NP first checked in
-
- To Do:
- */
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
- /*
- ©Apple Computer, Inc. 1992
- All Rights Reserved.
- Author: Eric House
-
- AEObjectPacking.p
- Object Support code for AppleEvents
- */
- #include <Types.h>
- #include <AEObjects.h>
- #include "OSLPriv.h"
-
- /* AEObject packing is a collection of routines which facilitate packing the descriptors
- for object specifiers. The basic routines clean up after themselves, and also clean up
- descriptors passed to them if requested. The cleanup of passed descriptors DOES NOT
- happen if the routine fails.
-
- Change History:
- Original Code by Mike Farr & Kurt Piersol 10/31/90
-
- */
-
-
- /*—————————————————————————————————— INLINE ———————————————————————————————————————*/
-
- /*$S AEObjPacking */
- /*——————————————————————————————————— EXTERNAL ——————————————————————————————————————*/
- /*$ifC Debug */
- extern void ReportError(Str255 errString, OSErr theError );
- /*$ENDC Debug */
-
- /*————————————————————————————— FORWARD DECLARATIONS ————————————————————————————————*/
-
- /* The first param of PutTypeParam() was const -- but PutTypeParam()
- passed the params along to AEPutKeyPtr(), whose first param is not const
- therefore , I decided to remove the const, instead of just letting CW ignore
- the fact...Adkins -- I remnoved the const.*/
-
- OSErr PutTypeParam( AERecord *theRecord, AEKeyword field, DescType theType) ;
-
-
- /*————————————————————————————————— PROCEDURES ——————————————————————————————————————*/
- /*———————————————————————————————————————————————————————————————————————————————————*/
-
- #pragma segment AEObjPacking
-
- pascal OSErr
- CreateCompDescriptor( DescType comparisonOperator,
- AEDesc *operand1,
- AEDesc *operand2,
- Boolean disposeInputs,
- AEDesc *theDescriptor)
- {
- /*Like the makeObjDescriptor routine above, this a handy packing routine. It has the same
- characteristics and limitations. However, it packs up a comparison record*/
-
- AERecord compRecord ;
- OSErr result ;
-
- compRecord.dataHandle = NULL;
-
- FailErr( AECreateList( NULL, 0, true, &compRecord ), result, errExit ); /*create the record.*/
-
- /*Pack the comparison operator*/
- FailErr( AEPutKeyPtr( &compRecord, keyAECompOperator, typeEnumerated,
- (Ptr)&comparisonOperator, sizeof(comparisonOperator) ), result, errExit ) ;
-
- /*Pack operand 1, the left hand side*/
- FailErr( AEPutKeyDesc( &compRecord, keyAEObject1, operand1 ), result, errExit ) ;
-
- /*Pack operand 2, the right hand side*/
- FailErr( AEPutKeyDesc( &compRecord, keyAEObject2, operand2 ), result, errExit ) ;
-
- /*autodispose if requested*/
- if ( disposeInputs )
- {
- IgnoreOSErr( AEDisposeDesc( operand1 ) ) ;
- IgnoreOSErr( AEDisposeDesc( operand2 ) ) ;
- }
-
- /*coerce record to descriptor*/
- result = AECoerceDesc( &compRecord, typeCompDescriptor, theDescriptor ) ;
- IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
- return result ;
-
- errExit :
-
- #ifdef Debug
- ReportError('comparison desc could not be made',err);
- #endif
- /*dispose record we created*/
- IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
-
- return result ;
- }
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
- pascal OSErr
- CreateCompEventDesc( DescType compEventClass,
- DescType compEventID,
- AERecord *args,
- Boolean disposeInputs,
- AEDesc *theDescriptor )
- {
- AERecord compRecord ;
- OSErr err = noErr ;
-
- compRecord.dataHandle = NULL ;
-
- FailErr( AECreateList( NULL, 0, true, &compRecord ), err, errExit ) ;
-
- // stuff in the event class and id (these are not attributes!!!)
- FailErr( AEPutKeyPtr( &compRecord, keyEventClassParam, typeType,
- (Ptr)&compEventClass, sizeof(compEventClass) ), err, errExit ) ;
-
- FailErr( AEPutKeyPtr( &compRecord, keyEventIDParam, typeType,
- (Ptr)&compEventID, sizeof(compEventID) ), err, errExit ) ;
-
- // Stuff in the params
- FailErr( AEPutKeyDesc( &compRecord, keyCompEvtParams, args ),
- err, errExit ) ;
-
- // autodispose if requested
- if ( disposeInputs )
- {
- IgnoreOSErr( AEDisposeDesc( args ) ) ;
- }
-
- // coerce record to descriptor
- FailErr( AECoerceDesc( &compRecord, typeCompEvtDescriptor, theDescriptor ),
- err, errExit ) ;
- IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
-
- FAIL_ERR_PROC(err, errExit)
- // no need to check if non-null
- IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
- END_FAIL_ERR_PROC(err)
- }
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
-
- pascal OSErr CreateOffsetDescriptor(
- long theOffset ,
- AEDesc *theDescriptor )
-
- {
- return AECreateDesc( typeLongInteger, (Ptr)&theOffset, 4, theDescriptor ) ;
- }
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
- pascal OSErr
- CreateLogicalDescriptor(
- AEDescList *theLogicalTerms, /*a list of comb and logi terms*/
- DescType theLogicOperator, /*the operator, e.g. AND*/
- Boolean disposeInputs,
- AEDesc *theDescriptor ) /*the result, a LogicalRecord*/
- {
- AERecord theRecord ;
- OSErr err ;
-
- theRecord.dataHandle = NULL;
- FailErr( AECreateList(NULL, 0, true, &theRecord ), err, errExit ) ; /*Make the record*/
-
- /*now stuff the terms of the logical combination*/
- FailErr( AEPutKeyDesc( &theRecord, keyAELogicalTerms, theLogicalTerms),
- err, errExit ) ;
-
- /*stuff the logical combination operator*/
- FailErr(AEPutKeyPtr( &theRecord, keyAELogicalOperator, typeEnumerated,
- (Ptr)&theLogicOperator, sizeof(theLogicOperator)), err, errExit );
-
- /*autodispose if requested*/
- if ( disposeInputs )
- IgnoreOSErr( AEDisposeDesc(theLogicalTerms) );
-
- /*coerce record to descriptor*/
- err = AECoerceDesc( &theRecord, typeLogicalDescriptor, theDescriptor ) ;
-
-
- errExit :
-
- /*dispose record we created*/
- IgnoreOSErr( AEDisposeDesc( &theRecord ) ) ;
- return err ;
- } /* CreateLogicalDescriptor */
-
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
- pascal OSErr CreateObjSpecifier( DescType desiredClass,
- AEDesc *theContainer,
- DescType keyForm ,
- AEDesc *keyData,
- Boolean disposeInputs,
- AEDesc *objSpecifier )
-
- /*The primary utility routine, this packages up the parameters and makes a complete
- object specifier out of them. It may also perform some storage management tasks, if
- the client so requests.*/
-
- {
- AERecord objRecord;
- OSErr err ;
-
- objRecord.dataHandle = NULL;
- FailErr(AECreateList( NULL, 0, true, &objRecord ), err, errExit );
-
- /*Pack the desired type.*/
- FailErr( PutTypeParam( &objRecord, keyAEDesiredClass, desiredClass), err, errExit ) ;
-
- /*pack the descriptor of the containing object*/
- FailErr( AEPutKeyDesc( &objRecord, keyAEContainer, theContainer ), err, errExit );
-
- /*if client asked for inputs to be disposed, toss them away. No errors should be possible!*/
- if ( disposeInputs )
- IgnoreOSErr( AEDisposeDesc( theContainer ) ) ;
-
- /*pack the selection form (or naming form)*/
- FailErr( AEPutKeyPtr( &objRecord, keyAEKeyForm, typeEnumerated, (Ptr)&keyForm, 4 ), err, errExit ) ;
-
- /*pack the selection data*/
- FailErr(AEPutKeyDesc( &objRecord, keyAEKeyData, keyData ), err, errExit ) ;
-
- /*again, an automatic and supposedly successful dispose*/
- if ( disposeInputs )
- IgnoreOSErr( AEDisposeDesc( keyData ) ) ;
-
- /* Lastly, turn our painstakingly constructed record into an object descriptor */
- err = AECoerceDesc( &objRecord, typeObjectSpecifier, objSpecifier ) ;
-
-
- errExit:
- /*dispose record we created*/
- IgnoreOSErr( AEDisposeDesc( &objRecord ) ) ;
- return err ;
- }
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
- pascal OSErr CreateRangeDescriptor(
- AEDesc *rangeStart , /*either a number or 'prev', 'next' etc.*/
- AEDesc *rangeStop , /*tells you which one it is*/
- Boolean disposeInputs ,
- AEDesc *theDescriptor ) /*the result, a rangeRecord*/
- {
- AERecord theRecord ;
- OSErr err ;
-
-
- theRecord.dataHandle = NULL ;
- FailErr( AECreateList( NULL, 0, true, &theRecord ), err, errExit ); /*Make the record*/
-
- /*now stuff the start and stop objects*/
- FailErr( AEPutKeyDesc( &theRecord, keyAERangeStart, rangeStart), err, errExit);
- FailErr( AEPutKeyDesc( &theRecord, keyAERangeStop, rangeStop), err, errExit);
-
- /*autodispose if requested*/
- if ( disposeInputs )
- {
- IgnoreOSErr(AEDisposeDesc(rangeStart));
- IgnoreOSErr(AEDisposeDesc(rangeStop)) ;
- }
-
- /*coerce record to descriptor*/
- err = AECoerceDesc( &theRecord, typeRangeDescriptor, theDescriptor);
-
- errExit:
- IgnoreOSErr( AEDisposeDesc( &theRecord ) ) ;
- return err ;
- }
-
- /*———————————————————————————————————————————————————————————————————————————————————*/
-
- /* Adkins -- I removed the const on the first param, case AEPutKeyPtr does not
- take a const param. CW ignores this apparently...*/
-
- static OSErr PutTypeParam( AERecord *theRecord, AEKeyword field, DescType theType )
-
- /*a handy utility routine to put a 4 chr parameter of typeType into an AERecord.*/
- {
- return AEPutKeyPtr( theRecord, field, typeType, (Ptr)&theType, 4 ) ;
- }
-